home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / pippki.jar / content / pippki / editcerts.js < prev    next >
Encoding:
Text File  |  2002-04-09  |  5.9 KB  |  195 lines

  1. /*
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is mozilla.org code.
  13.  *
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation.  Portions created by Netscape are
  16.  * Copyright (C) 2001 Netscape Communications Corporation. All
  17.  * Rights Reserved.
  18.  *
  19.  * Contributor(s):
  20.  *  Bob Lord <lord@netscape.com>
  21.  *  Ian McGreer <mcgreer@netscape.com>
  22.  */
  23.  
  24. const nsIX509Cert = Components.interfaces.nsIX509Cert;
  25. const nsX509CertDB = "@mozilla.org/security/x509certdb;1";
  26. const nsIX509CertDB = Components.interfaces.nsIX509CertDB;
  27. const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock;
  28.  
  29. var certdb;
  30. var cert;
  31.  
  32. function setWindowName()
  33. {
  34.   var dbkey = self.name;
  35.  
  36.   //  Get the cert from the cert database
  37.   certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
  38.   //var pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);
  39.   //var isupport = pkiParams.getISupportAtIndex(1);
  40.   //cert = isupport.QueryInterface(nsIX509Cert);
  41.   cert = certdb.getCertByDBKey(dbkey, null);
  42.  
  43.   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  44.   var windowReference = document.getElementById('editCaCert');
  45.  
  46.   var message1 = bundle.formatStringFromName("editTrustCA",
  47.                                              [ cert.commonName ],
  48.                                              1);
  49.   setText("certmsg", message1);
  50.  
  51.   var ssl = document.getElementById("trustSSL");
  52.   if (certdb.getCertTrust(cert, nsIX509Cert.CA_CERT, 
  53.                           nsIX509CertDB.TRUSTED_SSL)) {
  54.     ssl.setAttribute("checked", "true");
  55.   } else {
  56.     ssl.setAttribute("checked", "false");
  57.   }
  58.   var email = document.getElementById("trustEmail");
  59.   if (certdb.getCertTrust(cert, nsIX509Cert.CA_CERT, 
  60.                           nsIX509CertDB.TRUSTED_EMAIL)) {
  61.     email.setAttribute("checked", "true");
  62.   } else {
  63.     email.setAttribute("checked", "false");
  64.   }
  65.   var objsign = document.getElementById("trustObjSign");
  66.   if (certdb.getCertTrust(cert, nsIX509Cert.CA_CERT,  
  67.                           nsIX509CertDB.TRUSTED_OBJSIGN)) {
  68.     objsign.setAttribute("checked", "true");
  69.   } else {
  70.     objsign.setAttribute("checked", "false");
  71.   }
  72.   
  73.   window.sizeToContent();
  74. }
  75.  
  76. function doOK()
  77. {
  78.   var ssl = document.getElementById("trustSSL");
  79.   var email = document.getElementById("trustEmail");
  80.   var objsign = document.getElementById("trustObjSign");
  81.   var trustssl = (ssl.checked) ? nsIX509CertDB.TRUSTED_SSL : 0;
  82.   var trustemail = (email.checked) ? nsIX509CertDB.TRUSTED_EMAIL : 0;
  83.   var trustobjsign = (objsign.checked) ? nsIX509CertDB.TRUSTED_OBJSIGN : 0;
  84.   //
  85.   //  Set the cert trust
  86.   //
  87.   certdb.setCertTrust(cert, nsIX509Cert.CA_CERT, 
  88.                       trustssl | trustemail | trustobjsign);
  89.   window.close();
  90. }
  91.  
  92. function doLoadForSSLCert()
  93. {
  94.   var dbkey = self.name;
  95.  
  96.   //  Get the cert from the cert database
  97.   certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
  98.   cert = certdb.getCertByDBKey(dbkey, null);
  99.  
  100.   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  101.   var windowReference = document.getElementById('editWebsiteCert');
  102.  
  103.   var message1 = bundle.formatStringFromName("editTrustSSL",
  104.                                              [ cert.commonName ],
  105.                                              1);
  106.   setText("certmsg", message1);
  107.  
  108.   setText("issuer", cert.issuerName);
  109.  
  110.   var cacert = getCaCertForServerCert(cert);
  111.   if(cacert == null)
  112.   {
  113.      setText("explainations",bundle.GetStringFromName("issuerNotKnown"));
  114.   }
  115.   else if(certdb.getCertTrust(cacert, nsIX509Cert.CA_CERT,
  116.                                                 nsIX509CertDB.TRUSTED_SSL))
  117.   {
  118.      setText("explainations",bundle.GetStringFromName("issuerTrusted"));
  119.   }
  120.   else
  121.   {
  122.      setText("explainations",bundle.GetStringFromName("issuerNotTrusted"));
  123.   }
  124. /*
  125.   if(cacert == null)
  126.   {
  127.      var editButton = document.getElementById('editca-button');
  128.      editButton.setAttribute("disabled","true");
  129.   }
  130. */  
  131.   var trustssl = document.getElementById("trustSSLCert");
  132.   var notrustssl = document.getElementById("dontTrustSSLCert");
  133.   if (certdb.getCertTrust(cert, nsIX509Cert.SERVER_CERT, 
  134.                           nsIX509CertDB.TRUSTED_SSL)) {
  135.     trustssl.radioGroup.selectedItem = trustssl;
  136.   } else {
  137.     trustssl.radioGroup.selectedItem = notrustssl;
  138.   }
  139.   
  140.   window.sizeToContent();
  141. }
  142.  
  143. function doSSLOK()
  144. {
  145.   var ssl = document.getElementById("trustSSLCert");
  146.   //var checked = ssl.getAttribute("value");
  147.   var trustssl = ssl.selected ? nsIX509CertDB.TRUSTED_SSL : 0;
  148.   //
  149.   //  Set the cert trust
  150.   //
  151.   certdb.setCertTrust(cert, nsIX509Cert.SERVER_CERT, trustssl);
  152.   window.close();
  153. }
  154.  
  155. function editCaTrust()
  156. {
  157.    var cacert = getCaCertForServerCert(cert);
  158.    if(cacert != null)
  159.    {
  160.       window.openDialog('chrome://pippki/content/editcacert.xul', cacert.dbKey,
  161.                                'chrome,resizable=1,modal');
  162.    }
  163.    else
  164.    {
  165.       var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  166.       alert(bundle.GetStringFromName("issuerCertNotFound"));
  167.    }
  168. }
  169.  
  170. function getCaCertForServerCert(cert)
  171. {
  172.    var i=1;
  173.    var nextCertInChain;
  174.    nextCertInChain = cert;
  175.    var lastSubjectName="";
  176.    while(true)
  177.    {
  178.      if(nextCertInChain == null)
  179.      {
  180.         return null;
  181.      }
  182.      if((nextCertInChain.type == nsIX509Cert.CA_CERT) || 
  183.                                  (nextCertInChain.subjectName = lastSubjectName))
  184.      {
  185.         break;
  186.      }
  187.  
  188.      lastSubjectName = nextCertInChain.subjectName;
  189.      nextCertInChain = nextCertInChain.issuer;
  190.    }
  191.  
  192.    return nextCertInChain;
  193. }
  194.  
  195.